#!/bin/bash

#chkconfig: 345 79 50
#description: Start fakes3

if [[ ! -d /var/s3_files ]]; then
  mkdir /var/s3_files || return 1
 # chown -R vagrant:vagrant /var/s3_files # make it user-writable
fi

case $1 in
  start)
    echo "Starting fakes3"
    nohup /usr/local/bin/fakes3 -r /var/s3_files -p 1234 >> /var/log/fakes3.log 2>&1 &
    echo $! > /var/run/fakes3.pid
    ;;
  stop)
    echo "Stopping fakes3"
    if [ -f /var/run/fakes3.pid ]; then
	pid=`cat /var/run/fakes3.pid`
        kill -9 ${pid} > /dev/null
    fi
    ;;
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;
esac
